﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Net;
using System.IO;

namespace CodeBuilder
{
    public class Config
    {
       
        private static Ini ini;
        private static string Section;
        private static string sPath = @"\CodeGenerate.AddinConfig.ini";
        /// <summary>
        /// 获取配置文件路径
        /// </summary>
        /// <returns></returns>
        public static string GetConfigPath()
        {
            return  Environment.CurrentDirectory + sPath; ;
        }

        static Config()
        {
            ini = new Ini(GetConfigPath());
            Section = "CodeGenerate";
        }

        /// <summary>
        /// 参数初始化
        /// </summary>
        public static void Init()
        {
            //File.Create(GetConfigPath());
            ServerUrl = "http://192.168.3.123:9000/Framework/service.svc";
            //ServerUrl = "http://localhost/CodeBuilderService/service.svc";
            //ServerUrl = "http://10.10.15.252/CodeGenerateService/service.svc";
            Author = System.Net.Dns.GetHostName();
        }

        public static string ServerUrl
        {
            get
            {
                string temp= ini.IniReadValue(Section, "ServerUrl");
                if (string.IsNullOrEmpty(temp))
                {
                    throw new Exception("ServerUrl Config not find");
                }
                return temp;
            }
            set
            {
                ini.IniWriteValue(Section, "ServerUrl", value);
            }
       
        }

        public static string Author
        {
            get
            {
                string Temp = ini.IniReadValue(Section, "Author");
                if (string.IsNullOrEmpty(Temp))
                {
                    Temp = Dns.GetHostName();
                }
                return Temp;
            }
            set
            {
                ini.IniWriteValue(Section, "Author", value);
            }
        }


      
    }
}
